package com.sun.designpatternsdemo.adapter

import android.annotation.SuppressLint
import android.os.Bundle
import com.sun.designpatternsdemo.R
import com.sun.designpatternsdemo.adapter.bean.Mobile
import com.sun.designpatternsdemo.adapter.bean.V220Power
import com.sun.designpatternsdemo.adapter.bean.V5PowerAdapter
import com.sun.designpatternsdemo.app.AppConstant
import com.sun.designpatternsdemo.app.EMTagHandler
import com.sun.designpatternsdemo.base.BaseActivity
import com.sun.designpatternsdemo.databinding.ActivityAdapterBinding

/**
 * 定义：将一个类的接口转换成客户期望的另一个接口，适配器让原本接口不兼容的类可以相互合作。
 * 这个定义还好，说适配器的功能就是把一个接口转成另一个接口。
 * 如题目，手机充电器一般都是5V左右吧，咱天朝的家用交流电压220V，所以手机充电需要一个适配器（降压器）
 */
class AdapterActivity : BaseActivity<ActivityAdapterBinding>() {

    override fun layoutId(): Int = R.layout.activity_adapter

    @SuppressLint("SetTextI18n")
    override fun initView(savedInstanceState: Bundle?) {
        title = "适配器模式"
        mDataBind.apply {
            tvDefine.setText(EMTagHandler.fromHtml(AppConstant.ADAPTER_DEFINE))
            btAdapterText.text = "将220V家用电转换为5V"
            btAdapterText.setOnClickListener {
                val mobile = Mobile()
                val v5Power = V5PowerAdapter(V220Power())
                mobile.inputPower(v5Power)
            }
        }
    }
}